// Create the directory services.
angular.module('directoryServices', [])

/**
 * This causes the document to become stateful.
 * This means that any change to the URL will be saved in local storage,
 * when the user returns to the page, their last location will be restored.
 * @param {String} name The name of the directive.
 * @param  {Service} $rootScope The root scope of the application.
 * @param  {Service} $location The service that maintains the browser's URL.
 * @return {Function} The linking function that will be called.
 */
.factory('stateful', function($rootScope, $location) {
	// Update the local storage as the location changes.
	$rootScope.$watch(path, function(path) {
		localStorage.setItem('$$path', path);
	});

	/**
	 * Gets the $location's current path.
	 * @return {String} The $location's current path.
	 */
	function path() { 
		return $location.path(); 
	};
});